package com.example.rbacmanage.controller.background;

import com.example.rbacmanage.common.Result;
import com.example.rbacmanage.entity.app.ShopInfo;
import com.example.rbacmanage.service.app.ShopInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/background/shopinfo")
public class ShopInfoController {
    @Autowired
    private ShopInfoService shopInfoService;

    @GetMapping("/page")
    public Result page(ShopInfo shopInfo){
        return Result.success(shopInfoService.getPage(shopInfo));
    }

    @GetMapping("/list")
    public Result list(ShopInfo shopInfo){
        return Result.success(shopInfoService.getAll(shopInfo));
    }


    @GetMapping("/info/{id}")
    public Result info(@PathVariable Long id){
        return Result.success(shopInfoService.getById(id));
    }

    @PostMapping("/add")
    @PreAuthorize("hasAnyAuthority('background:shopinfo:add')")
    public Result add(@RequestBody ShopInfo shopInfo){
        shopInfoService.save(shopInfo);
        return Result.success();
    }

    @PutMapping("/update")
    @PreAuthorize("hasAnyAuthority('background:shopinfo:update')")
    public Result update(@RequestBody ShopInfo shopInfo){
        shopInfoService.update(shopInfo);
        return Result.success();
    }

    @DeleteMapping("/remove")
    @PreAuthorize("hasAnyAuthority('background:shopinfo:remove')")
    public Result remove(@RequestBody Long[] ids){
        shopInfoService.remove(ids);
        return Result.success();
    }
}
